﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using ITProject.Domain.Entities;

namespace ITProject.WebUI.Models.ProjectAdmin
{
    public class ProjectAdminEditReleaseViewModel
    {
        [Required(ErrorMessage = "Nazwa wersji jest wymagana")]
        [MinLength(4, ErrorMessage = "Nazwa wersji musi posiadać co najmniej 4 znaki")]
        [Display(Name = "Nazwa")]
        public string Name { get; set; }
        [Display(Name = "Opis wersji")]
        public string Description { get; set; }
        [DataType(DataType.Date)]
        [Display(Name = "Planowana data wydania wersji")]
        public DateTime PlannedEndDate { get; set; }

        // atrybuty ukryte w formularzu
        public string ProjectName { get; set; }
        public int ReleaseId { get; set; }

        public static ProjectAdminEditReleaseViewModel Convert(Release release, string projectName)
        {
            ProjectAdminEditReleaseViewModel vm = new ProjectAdminEditReleaseViewModel();
            vm.Name = release.Name;
            vm.PlannedEndDate = release.PlannedEndDate;
            vm.Description = release.Description;
            vm.ReleaseId = release.Id;
            vm.ProjectName = projectName;
            return vm;
        }

        public static Release Convert(ProjectAdminEditReleaseViewModel vm)
        {
            Release release = new Release();
            release.Name = vm.Name;
            release.PlannedEndDate = vm.PlannedEndDate;
            release.Description = vm.Description;
            release.Id = vm.ReleaseId;
            return release;
        }
    }
}